package com.sl.carcode.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.webkit.WebView;
import android.widget.ListView;

import com.alibaba.baichuan.android.trade.AlibcTrade;
import com.alibaba.baichuan.android.trade.model.AlibcShowParams;
import com.alibaba.baichuan.android.trade.model.OpenType;
import com.alibaba.baichuan.android.trade.page.AlibcAddCartPage;
import com.alibaba.baichuan.android.trade.page.AlibcBasePage;
import com.alibaba.baichuan.android.trade.page.AlibcDetailPage;
import com.alibaba.baichuan.android.trade.page.AlibcPage;
import com.alibaba.baichuan.trade.biz.AlibcConstants;
import com.alibaba.baichuan.trade.biz.core.taoke.AlibcTaokeParams;
import com.sl.carcode.DemoTradeCallback;
import com.sl.carcode.R;
import com.sl.carcode.adapter.GoodLVAdapter;
import com.sl.carcode.bean.GoodInfo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class DetailActivity extends AppCompatActivity {

    private Map<String, String> exParams = new HashMap();
    private GoodLVAdapter goodLVAdapter;
    private ListView lv;
    private GoodInfo goodInfo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail);
        goodInfo = (GoodInfo) getIntent().getSerializableExtra("Good");
        initView();
    }

    private ArrayList<GoodInfo> list = new ArrayList();

    @Override
    protected void onStart() {
        super.onStart();
    }

    private void initView() {

        Map<String, String> exParams = new HashMap<>();
        exParams.put(AlibcConstants.ISV_CODE, "appisvcode");
//        商品详情page
        AlibcBasePage detailPage = new AlibcDetailPage(goodInfo.getID());
////        实例化店铺打开page
//        AlibcBasePage shopPage = new AlibcShopPage(shopId);
//
//        实例化添加购物车打开page
//        AlibcBasePage addCardPage = new AlibcAddCartPage(goodInfo.getGoodsID());
////        实例化我的订单打开page
//        AlibcBasePage ordersPage = new AlibcMyOrdersPage(status, allOrder);
//
////        实例化我的购物车打开page
//        AlibcBasePage myCartsPage = new AlibcMyCartsPage();
//
////        实例化URL打开page
//        AlibcBasePage page = new AlibcPage(goodInfo.getQuan_id());

//        设置页面打开方式
        AlibcShowParams showParams = new AlibcShowParams(OpenType.Native, false);
        WebView webView = (WebView) findViewById(R.id.wv);
//      AlibcTaokeParams alibcTaokeParams = new AlibcTaokeParams("mm_128779697_0_0", "mm_128779697_0_0", "mm_128779697_0_0"); // 若非淘客taokeParams设置为null即可
        AlibcTaokeParams alibcTaokeParams = new AlibcTaokeParams(); // 若非淘客taokeParams设置为null即可
        alibcTaokeParams.pid = "mm_128779697_0_0";
        alibcTaokeParams.subPid = "mm_128779697_0_0";
        AlibcBasePage alibcBasePage = new AlibcDetailPage(goodInfo.getGoodsID());
        AlibcShowParams alibcShowParams = new AlibcShowParams(OpenType.H5, false);
        exParams.put("isv_code", "appisvcode");
        exParams.put("alibaba", "阿里巴巴");
        AlibcTrade.show(DetailActivity.this, webView, null, null, alibcBasePage, alibcShowParams, alibcTaokeParams, exParams, new DemoTradeCallback());
//        获取淘宝用户信息
//        AlibcTrade.show(this, webView, webViewClient, webChromeClient, tradePage, showParams, taokeParams, trackParam, new AlibcTradeCallback() {
//
//            @Override
//            public void onTradeSuccess(AlibcTradeResult alibcTradeResult) {
//
//            }
//
//            @Override
//            public void onFailure(int code, String msg) {
//                //打开电商组件，用户操作中错误信息回调。code：错误码；msg：错误信息
//            }
//        });
    }
}
